package service

import (
	"daily-blog/dao"
	"daily-blog/global"
	"daily-blog/model"
	"daily-blog/pkg"
)

func CreateCategory(category *model.Category) bool {
	category.CategoryId = pkg.GenUUID()
	if err := dao.CreateCategory(category); err != nil {
		global.GVA_LOG.Error(err.Error())
		return false
	}
	return true
}

func DeleteCategoryById(categoryId string) bool {
	if err := dao.DeleteCategoryById(categoryId); err != nil {
		global.GVA_LOG.Error(err.Error())
		return false
	}
	return true
}

func GetCategoryList() ([]model.CategoryInfo, bool) {
	tagList, err := dao.GetCategoryList()
	if err != nil {
		global.GVA_LOG.Error(err.Error())
		return nil, false
	}
	return tagList, true
}

func UpdateCategory(categoryId, categoryName, categoryDesc, categoryImage string) bool {
	if err := dao.UpdateCategory(categoryId, categoryName, categoryDesc, categoryImage); err != nil {
		global.GVA_LOG.Error(err.Error())
		return false
	}
	return true
}
